package com.tdkj.service.shop.impl;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.tdkj.dao.shop.IBeanShopNoticeDao;
import com.tdkj.model.shop.BeanShopNotice;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.BaseService;
import com.tdkj.service.shop.IBeanShopNoticeService;

@Component
public class BeanShopNoticeServiceImpl extends BaseService implements
		IBeanShopNoticeService {
	
	private  IBeanShopNoticeDao beanShopNoticeDao;
    
	@Resource
	public void setBeanShopNoticeDao(IBeanShopNoticeDao beanShopNoticeDao) {
		this.beanShopNoticeDao = beanShopNoticeDao;
	}


	@Override
	public BeanShopNotice add(String title, String content, Long userId) {
		BeanUser user = beanShopNoticeDao.findById(userId, BeanUser.class);
		BeanShopNotice bean = new BeanShopNotice();
		bean.setTitle(title);
		bean.setUser(user);
		bean.setContent(content);
		bean.setPublishTime(new Date(System.currentTimeMillis()));
		beanShopNoticeDao.save(bean);
		return bean;
	}

	@Override
	public void update(Long id, String title, String content, Long userId) {
		BeanUser user = beanShopNoticeDao.findById(userId, BeanUser.class);
		BeanShopNotice bean = beanShopNoticeDao.findById(id, BeanShopNotice.class);
		bean.setTitle(title);
		bean.setUser(user);
		bean.setContent(content);
		bean.setPublishTime(new Date(System.currentTimeMillis()));
	}

}
